/*******************************************************************
 *                                                                 *
 *  rpcsds.h                                                       *
 *                                                                 *
 *  This file is a part of the eXtremeDB source code               *
 *  Copyright (c) 2001-2012 McObject LLC                           * 
 *  All Rights Reserved                                            *
 *                                                                 *
 *******************************************************************/

#ifndef _MCO_RPC_SERIALIZATION_DESERIALIZATION_H
    #define _MCO_RPC_SERIALIZATION_DESERIALIZATION_H

    #ifdef __cplusplus
    extern "C" {
    #endif 

    #include <rpcctx.h>
    #ifdef __KERNEL__
        #include <mcosync_ke.h>
    #endif /*  */
    typedef struct tag_mco_rpc_serialize
    {
        unsigned int type_i;
        void* ptr;
    } mco_rpc_serialize_t, * mco_rpc_serialize_p;

    typedef int(*mcorpc_write_stream_t)(void* buf, unsigned int buf_sz, void* param, unsigned int network_order);
    typedef int(*mcorpc_read_stream_t)(void* buf, unsigned int buf_sz, void* param, unsigned int network_order,
                unsigned int* read_sz);

    int mcorpc_serialize(mco_rpc_context_p ctx, mco_rpc_serialize_t* desc, unsigned int n_desc, mcorpc_write_stream_t
                         wp, void* param);

    int mcorpc_deserialize(mco_rpc_context_p ctx, mcorpc_read_stream_t rp, void* param, mco_rpc_serialize_t* desc,
                           unsigned int n_desc);

    int mco_rpc_clear(mco_rpc_context_p ctx, mco_rpc_serialize_t* desc);

    void mco_rpc_fatal_error(int err_code);


    typedef void* (*mcorpc_malloc_t)( mco_size_t sz);
    typedef void (*mcorpc_free_t)( void* p);
    
    #define MCO_RPC_EVT_SERIALIZE        1 
    #define MCO_RPC_EVT_DESERIALIZE   2
    typedef int (*mcorpc_event_t)( int ev_type, void* param);
    
    int mcorpc_register_event_handler(mcorpc_event_t pevt_handler, void* param);

    #ifdef __cplusplus
    }
    #endif 

#endif /* _MCO_RPC_SERIALIZATION_DESERIALIZATION_H */
